class CreateTickets < ActiveRecord::Migration
  def self.up
    create_table :tickets do |t|
      t.string :pnr                         ,:default => '',:limit => 10
      t.string :ticket_no                   ,:default => '',:limit => 20  #票号
      t.integer :order_id                   #订单号
      t.integer :customer_id                ,:default => 1
      
      t.string :status                      ,:default => '',:limit => 16  #状态
      t.string :status_type                 ,:default => '',:limit => 10  #票状态代码 HK RR
      t.string :ticket_type                 ,:default => '',:limit => 10  #机票类型 婴儿 儿童
      t.string :trip_type                   ,:default => '',:limit => 10  #单程 往返 联程
      
      t.string :air_no                      ,:default => '',:limit => 10  #航班号
      t.string :fromto                      ,:default => '',:limit => 6  #航程
      t.date :fly_date                      #起飞日期
      t.string :fly_time                    ,:default => '',:limit => 10  #起飞时间
      t.string :arr_time                    ,:default => '',:limit => 10  #到达时间
      t.string :plane_type                  ,:default => '',:limit => 10  #飞机型号
      t.string :position                    ,:default => '',:limit => 10  #舱位
      
      t.integer :passenger_id               ,:default => 1 #常旅客id
      
      t.integer :price                      ,:default => 0 ,:limit => 2#机票价格
      t.integer :price_F                    ,:default => 0 ,:limit => 2#机票F 返现
      t.integer :fuel_tax                   ,:default => 0 ,:limit => 2#附加费
      t.integer :airdrome_tax               ,:default => 0 ,:limit => 2#机场费税
      t.integer :insurance_F                ,:default => 0 ,:limit => 2#保险返利
      t.integer :other                      ,:default => 0 ,:limit => 2#其他
      t.integer :total_price                ,:default => 0 ,:limit => 2#总价
      t.integer :point                      ,:default => 0 ,:limit => 2#积分
      
      t.integer :insurance_outer_id         ,:default => 1 ,:limit => 2 #出保险人编号
      t.datetime :insurance_out_date        #出保险时间
      t.string :insurance_company           ,:default => '',:limit => 18 #保险公司名称 一般16位
      t.string :insurance_no                ,:default => '',:limit => 18 #保单号 一般16位
      t.string :insurance_type              ,:default => '',:limit => 10 #保单类型 一般16位
      t.integer :insurance_number           ,:limit => 1 ,:default => 0 #保单份数  
      t.string :insurance_print_times       ,:limit => 1 ,:default => 0 #保单打印次数 备注
      
      t.integer :canceler_id                ,:default => 1 ,:limit => 2#取消员
      t.datetime :cancel_date               #取消时间
      t.string :cancel_reason               ,:default => '',:limit => 60  #取消原因
      
      t.integer :rake_off                   ,:default => 3 ,:limit => 1#代理费比率
      t.integer :policy_id                  #政策id
      t.integer :is_locked                  ,:limit => 1 ,:default => 0 #是否管理会要锁定 1为True 0为False
      
      t.integer :father_id                  #婴儿监护人的票id
      t.integer :lock_version               ,:default => 0 #乐观锁
      t.timestamps
    end
    
    #add_index :tickets, :order_id
    
    Ticket.create(:pnr => 'AAAAA',:ticket_no => '',:order_id => '1',:customer_id=>2,:price => '200',:total_price =>330,:status =>'未确认',:air_no => 'SC5671',:fromto => 'TAOPEK',:fly_date => '2008-09-09',:fly_time => '13:00',:passenger_id =>2,:position => 'Y',:fuel_tax => '60',:airdrome_tax => '50',:insurance_number=>1 )
    Ticket.create(:pnr => 'AAAAA',:ticket_no => '',:order_id => '1',:customer_id=>2,:price => '300',:total_price =>430,:status =>'未确认',:air_no => 'SC5671',:fromto => 'TAOPEK',:fly_date => '2008-09-09',:fly_time => '13:00',:passenger_id =>3,:position => 'Y',:fuel_tax => '60',:airdrome_tax => '50',:insurance_number=>1 )
    Ticket.create(:pnr => 'BBBBB',:ticket_no => '',:order_id => '2',:customer_id=>2,:price => '800',:total_price =>930,:status =>'确认出票',:air_no => 'SC2233',:fromto => 'PEKTAO',:fly_date => '2008-09-09',:fly_time => '12:00',:passenger_id =>3,:position => 'B',:fuel_tax => '60',:airdrome_tax => '50',:insurance_number=>1 )
    Ticket.create(:pnr => 'CCCCC',:ticket_no => '',:order_id => '3',:customer_id=>2,:price => '1000',:total_price =>1130,:status =>'立即出票',:air_no => 'CA998',:fromto => 'TAOSHA',:fly_date => '2008-09-09',:fly_time => '09:00',:passenger_id =>3,:position => 'V',:fuel_tax => '60',:airdrome_tax => '50',:insurance_number=>1 )
    Ticket.create(:pnr => 'EEEEE',:ticket_no => '',:order_id => '4',:customer_id=>1,:price => '300',:total_price =>430,:status =>'未确认',:air_no => 'MU5197',:fromto => 'TAOCAN',:fly_date => '2008-09-09',:fly_time => '11:00',:passenger_id =>3,:position => 'H',:fuel_tax => '60',:airdrome_tax => '50',:insurance_number=>1 )
    Ticket.create(:pnr => 'FFFFF',:ticket_no => '123-1234567891',:order_id => '5',:customer_id=>2,:price => '800',:total_price =>930,:status =>'已出票',:air_no => 'MU5195',:fromto => 'TAOPEK',:fly_date => '2008-09-09',:fly_time => '15:00',:passenger_id =>4,:position => 'F',:fuel_tax => '60',:airdrome_tax => '50',:insurance_number=>1 )
    Ticket.create(:pnr => 'FFFFF',:ticket_no => '123-1234567890',:order_id => '5',:customer_id=>2,:price => '1000',:total_price =>1130,:status =>'已出票',:air_no => 'MU5195',:fromto => 'TAOPEK',:fly_date => '2008-09-09',:fly_time => '15:00',:passenger_id =>1,:position => 'C',:fuel_tax => '60',:airdrome_tax => '50',:insurance_number=>1 )
  
  end

  def self.down
    drop_table :tickets
  end
end
